<style type="text/css">
td input {float:left}
td span.error {position:static;float:left}
</style>
<link
	href="${rc.getContextPath()}/manage/css/dwzCustomCss/dwz.custom.css?v=${ver}"
	rel="stylesheet" type="text/css">
<div class="pageContent">
	<form method="post"
		action="${rc.getContextPath()}/manage/management/adminECode/saveECodeType"
		class="pageForm required-validate"
		onsubmit="return validateCallback(this, dialogAjaxDone);">
		<div class="pageFormContent">
			<input type="hidden" name="navTabId" value="${navTabId!''}">
			<dl>
				<dt>枚举码类型编号：</dt>
				<dd>
					<input name="eCodeType"<#if (eCodeType)??>
					value="${eCodeType.eCodeType!''}" readonly="readonly" <#else>
					remote="${rc.getContextPath()}/manage/management/adminECode/validateECodeType"
					warn="枚举码类型编号已经存在" </#if> type="text" maxlength="30"
					class="required toUp alphanumeric" size="150" />
				</dd>
			</dl>
			<dl>
				<dt>描述：</dt>
				<dd>
					<input name="typeText"<#if (eCodeType)??>
					value="${eCodeType.typeText!''}" </#if> type="text" maxlength="60"
					class="required" size="150" />
				</dd>
			</dl>
			<dl class="nowrap">
				<dt>备注：</dt>
				<dd>
					<input name="memo"<#if (eCodeType)??>
					value="${eCodeType.memo!''}" </#if> type="text" maxlength="255"
					class="" size="150" />
				</dd>
			</dl>
			<dl>
				<dt>&nbsp;</dt>
				<dd>
					<label><input type="checkbox" name="lockFlag" value="1"<#if
						eCodeType.lockFlag == 1> checked="true"</#if>>锁定</label>
				</dd>
			</dl>
			<dl class="nowrap">
				<dd>
					<div class="panel" currentIndex="0" eventType="click"
						style="width: 605px; margin: 0;">
						<h1>枚举码</h1>
						<div>
							<div id="bar" class="pBar">
								<ul class="toolBar">
									<li><a href="javascript:void(0);" class="add" width="660"
										height="510" name="btnECodeAdd"><span>新增</span> </a></li>
									<li><a href="javascript:void(0);" class="edit"
										name="btnECodeModify"><span>修改</span> </a></li>
									<li><a href="javascript:void(0);" class="delete"
										name="btnECodeDelete"><span>删除</span> </a></li>
								</ul>
							</div>
							<table class="table border" width="100%" layoutH="260">
								<thead>
									<tr>
										<th width="20"><input type="checkbox" group="ids"
											class="checkboxCtrl"></th>
										<th width="100">枚举码编码</th>
										<th width="100">描述</th>
										<th width="100">显示顺序</th>
										<th width="20">锁定</th>
									</tr>
								</thead>
								<tbody>
									<#if eCodeType.eCodeList??> <#list eCodeType.eCodeList as
									eCode>
									<tr>
										<td width="20"><input name="ids"
											value="${eCode.eCode!''}" type="checkbox"></td>
										<td width="100">${eCode.eCode!''}<input type="hidden" name="eCodeList[${eCode_index}].eCode" value="${eCode.eCode!''}" /></td>
										<td width="100">${eCode.eCodeText!''}<input type="hidden" name="eCodeList[${eCode_index}].eCodeText" value="${eCode.eCodeText!''}" /></td>
										<td width="100">${eCode.displayOrdinal!''}<input type="hidden" name="eCodeList[${eCode_index}].displayOrdinal" value="${eCode.displayOrdinal!''}" /></td>
										<td width="20"><input type="checkbox" value="1"<#if
											eCode.lockFlag == 1> checked</#if>/><input type="hidden" name="eCodeList[${eCode_index}].lockFlag" value="${eCode.lockFlag!''}" /></td>
									</tr>
									</#list> </#if>
								</tbody>
							</table>
						</div>
					</div>
				</dd>
			</dl>
		</div>
		<div class="formBar">
			<ul>
				<li><div class="buttonActive">
						<div class="buttonContent">
							<button type="submit" name="btnFormSave">保存</button>
						</div>
					</div></li>
				<li>
					<div class="buttonActiveGrey">
						<div class="buttonContent">
							<button type="button" class="close">取消</button>
						</div>
					</div>
				</li>
			</ul>
		</div>
	</form>
</div>
<script type="text/javascript">
(function($){
	var page = DWZ.context();
	//获取枚举码个数，用于后续新增或修改时的下标起始位
	var trIndex = $("table tbody tr",page).length;
	//获取表格表头的宽度
	var thWidthArray = [];
	//默认的枚举码页面DOM元素的公共配置，与页面表格的列数相对应
	var defaultECodeElConfigs = [{
		'name' : 'ids',
		'type' : 'checkbox'
	},{
		'type' : 'text',
		'maxlength' : '30',
		'class' : 'alphanumeric toUp required textInput'
	},{
		'type' : 'text',
		'maxlength' : '60',
		'class' : 'required textInput'
	},{
		'type' : 'text',
		'maxlength' : '10',
		'class' : 'digits textInput'
	},{
		'type' : 'checkbox',
		'value' : '1'
	}];
	
	//根据配置对象信息生成相应的INPUT元素HTML
	function generateECodeEl(elConfig){
		var inputHtml = '<input ';
		for(var configName in elConfig){
			inputHtml = inputHtml + configName+ '="'+elConfig[configName]+'" ';
		}
		inputHtml = inputHtml+" />"
		return inputHtml;
	}
	
	//根据配置对象信息及单元格配置字符串生成相应的TD元素HTML
	function generateECodeElTd(elConfig,tdConfigStr){
		var tdHtml = "<td style='width:"+tdConfigStr+"' >"+generateECodeEl(elConfig)+"</td>";
		return tdHtml;
	};
	
	//生成最新的枚举码页面DOM元素的配置，本方法统一管理元素的名称下标增长
	function generateDefaultIndexECodeElConfig(){
		var names = ["eCodeList["+trIndex+"].eCode",
		             "eCodeList["+trIndex+"].eCodeText",
		             "eCodeList["+trIndex+"].displayOrdinal",
		             "eCodeList["+trIndex+"].lockFlag"]
		
		var eCodeElConfigs = [];
		var eCodeElConfig;
		$.each(defaultECodeElConfigs,function(i,defaultElConfig){
			eCodeElConfig = $.extend({},defaultElConfig);
			if(0<i){
				eCodeElConfig["name"]=names[i-1];
			}
			eCodeElConfigs.push(eCodeElConfig);
		});
		
		trIndex++;
		return eCodeElConfigs;
	}
	
	//枚举码信息表格添加按钮事件绑定
	$("a[name='btnECodeAdd']",page).on("click",function(){
		var tbody=$($("table tbody",page)[0]);
		
		//初始化表格头信息
		if(0==thWidthArray.length){
			$.each($("table th",page),function(i,e){
				thWidthArray.push($(e).css("width"));
			});
		}

		var trHtml = "<tr edit='true'>";
		$.each(generateDefaultIndexECodeElConfig(),function(i,elConfig){
			trHtml = trHtml +generateECodeElTd(elConfig,thWidthArray[i]);
		})
		
		trHtml = trHtml + "</tr>";
		tbody.prepend(trHtml);
		
	});
	
	//枚举码信息表格修改按钮事件绑定
	$("a[name='btnECodeModify']",page).on("click",function(){
		//初始化表格头信息
		if(0==thWidthArray.length){
			$.each($("table th",page),function(i,e){
				thWidthArray.push($(e).css("width"));
			});
		}

		
		var selectedTrs = $("table tbody tr input[name='ids']:checked",page);
		
		if(0===selectedTrs.length){
			alertMsg.error('请勾选需要修改的记录。');
			return;
		}
		
		$.each(selectedTrs,function(i,e){
			var trEl = $(e).parents("tr:first");
			if('true'!==trEl.attr("edit")){
				//如果当前行被选中,且不处于编辑状态,循环取值，并进行元素参数赋值
				var eCodeElConfigs = generateDefaultIndexECodeElConfig();
				eCodeElConfigs[1]["readonly"]="true";
				var tdHtml = "";
				//遍历现有的数据单元格，取对应值生成相应单元格HTML
				$.each($("td",trEl),function(tdIndex,td){
					if(0<tdIndex && 4>tdIndex){
						eCodeElConfigs[tdIndex]["value"] = $(td).text();
					}else if(4==tdIndex){
						eCodeElConfigs[tdIndex]["checked"] = $("input",$(td)).attr("checked");
					}
					tdHtml += generateECodeElTd(eCodeElConfigs[tdIndex],thWidthArray[tdIndex]);
				});
				
				trEl.html(tdHtml);
				trEl.attr("edit","true");
			}
		});
	});
	
	//枚举码信息表格删除按钮事件绑定
	$("a[name='btnECodeDelete']",page).on("click",function(){
		
		var selectedTrs = $("table tbody tr input[name='ids']:checked",page);
		
		if(0===selectedTrs.length){
			alertMsg.error('请勾选需要删除的记录。');
			return;
		}
		
		$.each(selectedTrs,function(i,e){
			var trEl = $(e).parents("tr:first");
			var ecodeInput = $("td:eq(1) input",trEl);
			if(ecodeInput.attr("value")){
				trEl.hide();
				$("td:eq(0) input",trEl).attr("checked",false);
				ecodeInput.attr("value","{DELETE}_"+ecodeInput.attr("value"));
			}else{
				trEl.remove();
			}
		});
	});

})(jQuery);
</script>